package com.lyf.juc.practice.lock;

import java.util.concurrent.TimeUnit;

/**
 * @author LYF
 * @date 2022/7/3
 */
public class LockSupportTests {
    public static void main(String[] args) throws InterruptedException {

        Object o
                 = new Object();


        //o.wait();
        //o.notify();

        //Thread.sleep();
        //Thread.interrupted();
        //Thread.yield();

        Thread thread = new Thread(()->{
            while (true){
                System.out.println(Thread.currentThread().getName()+" exec.."+System.currentTimeMillis());
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1");

        thread.start();

         new Thread(()->{
             try {
                 TimeUnit.SECONDS.sleep(4);
                 thread.interrupt();
                 System.out.println(Thread.currentThread().getName()+" interrupt t1" );
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             while (true){
                 if(thread.isInterrupted())
                 {
                     //Thread.interrupted();
                     System.out.println("has interrupted...");
                     break;
                 }else{
                     try {
                         TimeUnit.SECONDS.sleep(1);
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }
                 }
             }


         },"t2").start();


        TimeUnit.SECONDS.sleep(100);



    }
}
